package com.welink.cmp.adapter.api.topotree;

import com.welink.cmp.domain.topotree.DeviceNetTopoDomain;
import com.welink.cmp.dto.IdQuery;
import com.welink.cmp.dto.metadata.AssetsNameQry;
import com.welink.cmp.dto.topotree.*;
import com.welink.cmp.topotree.NetTopologyAppService;
import com.welink.cmp.topotree.command.NetTopologyCmdExe;
import com.welink.common.dto.MultiResponse;
import com.welink.common.dto.Response;
import com.welink.common.dto.SingleResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 网络拓扑服务API
 *
 * @author yanwei li create  2024-05-24 17:34
 */
@RestController
@RequestMapping("/api/nettopo")
public class NetTopologyServiceApi {

    @Autowired
    private NetTopologyAppService netTopologyAppService;

    /**
     * [新增]构建网络拓扑关系
     * @return resultCode
     */
    @PostMapping("/build")
    public SingleResponse<Long> buildNetTopology(@RequestBody BuildNetTopologyAddCmd addCmd){
        return netTopologyAppService.buildNetTopology(addCmd);
    }

    /**
     * [修改] 修改当前机器的相邻机器信息
     * @param uptCmd 相邻机器信息
     * @return resultCode
     */
    @PostMapping("/modifyNext")
    public Response modifyNext(@RequestBody ModifyNetTopologyUptCmd uptCmd){
        return netTopologyAppService.modifyNext(uptCmd);
    }

    /**
     * [ID 查询] 查询当前节点下的交换机信息
     * @param nameQry ID
     * @return DTO
     */
    @GetMapping("/get-switch")
    public SingleResponse<DeviceNetTopoDomain> getSwitchNodesItemByName(@RequestBody AssetsNameQry nameQry){
        return netTopologyAppService.getSwitchNodesItemByName(nameQry);
    }

    /**
     * [列表查询] 获取所有子节点相邻机器
     * @param nameQry 机器名
     * @return 相邻机器名列表
     */
    @GetMapping("/get-host")
    public SingleResponse<DeviceNetTopoDomain> getHostNodesItemByName(@RequestBody AssetsNameQry nameQry){
        return netTopologyAppService.getHostNodesItemByName(nameQry);
    }

    /**
     * [拓扑树查询]
     */
    @GetMapping("/id")
    public SingleResponse<DeviceTopoNodeCO> expansionNodes(@RequestBody IdQuery idQuery){
        return SingleResponse.of(netTopologyAppService.expansionNodes(idQuery));
    }



}
